package com.zzyweb.rentalcarsys.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author zhiyi
 * @date 10/5/25
 **/

public class UserInfoProvider {
    public String selectUserByConditions(final String username, final String email, final String phoneNumber, final String name)  {
        return new SQL(){{
           SELECT("ua.id, ua.username,ua.email,ua.phone_number,ui.full_name,ui.identity_number,ui.profile_picture,ui.is_delete");
           FROM("user_account ua");
           JOIN("user_info ui on ua.id = ui.user_id");
           if (StringUtils.hasText(username)) {
               WHERE("ua.username = #{username}");
           }
           if (StringUtils.hasText(email)) {
               WHERE("ua.email = #{email}");
           }
           if (StringUtils.hasText(phoneNumber)) {
               WHERE("ua.phone_number = #{phoneNumber}");
           }
           if (StringUtils.hasText((name))) {
               WHERE("ui.full_name LIKE CONCAT('%', #{name}, '%')");
           };
           WHERE("ui.is_delete = 0");

        }}.toString();
    }
}
